package com.weitu.majorHazard.activityRecord.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.majorHazard.activityRecord.entity.ActivityRecord;
import com.weitu.majorHazard.activityRecord.entity.ProblemAssociation;
import com.weitu.majorHazard.activityRecord.mapper.ActivityRecordMapper;
import com.weitu.majorHazard.activityRecord.service.ActivityRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/4/24.
 */
@Service
public class ActivityRecordServiceImpl implements ActivityRecordService {
    private final ActivityRecordMapper activityRecordMapper;

    @Autowired
    public ActivityRecordServiceImpl(ActivityRecordMapper activityRecordMapper){
        this.activityRecordMapper=activityRecordMapper;
    }

    @Override
    public int queryCount(Map<String, Object> map) {
        return this.activityRecordMapper.queryCount(map);
    }

    @Override
    public List<ActivityRecord> queryList(Map<String, Object> map) {
        return this.activityRecordMapper.queryList(map);
    }

    @Override
    @Transactional
    public boolean insertActivityRecord(ActivityRecord activityRecord) {
        boolean flag= AccessoryUtil.saveAccerssoryInfo(activityRecord.getId());
        boolean flag2=false;
        int count=this.activityRecordMapper.insertActivityRecord(activityRecord);
        if(count==1){
            flag2=true;
        }
        return flag&&flag2;
    }

    @Override
    public ActivityRecord queryById(String id) {
        return this.activityRecordMapper.queryById(id);
    }

    @Override
    @Transactional
    public boolean insertProblemAssociation(ProblemAssociation problemAssociation) {
        boolean flag2=false;
        int count=this.activityRecordMapper.insertProblemAssociation(problemAssociation);
        if(count==1)
            flag2=true;
        boolean flag= AccessoryUtil.saveAccerssoryInfo(problemAssociation.getId());
        return flag&&flag2;
    }

    @Override
    public List<ProblemAssociation> queryProblemAssociation(String activityRecordId) {
        return this.activityRecordMapper.queryProblemAssociation(activityRecordId);
    }

    @Override
    public int deleteProblemAssociation(String id) {
        return this.activityRecordMapper.deleteProblemAssociation(id);
    }

    @Override
    public ProblemAssociation queryProblemAssociationById(String id) {
        return this.activityRecordMapper.queryProblemAssociationById(id);
    }

    @Override
    @Transactional
    public boolean updateProblemAssociation(ProblemAssociation problemAssociation) {
        boolean flag2=false;
        int count=this.activityRecordMapper.updateProblemAssociation(problemAssociation);
        if(count==1)
            flag2=true;
        boolean flag=AccessoryUtil.saveAccerssoryInfo(problemAssociation.getId());
        return flag2&&flag;
    }

    @Override
    @Transactional
    public boolean updateActivityRecord(ActivityRecord activityRecord) {
        boolean flag2=false;
        int count=this.activityRecordMapper.updateActivityRecord(activityRecord);
        if(count==1)
            flag2=true;
        boolean flag=AccessoryUtil.saveAccerssoryInfo(activityRecord.getId());
        return flag2&&flag;
    }
}
